package com.gxa.wmcrm.controller;

import com.alibaba.fastjson.JSON;
import com.gxa.wmcrm.entity.Department;
import com.gxa.wmcrm.service.DepartmentService;
import com.gxa.wmcrm.service.Impl.DepartmentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "DepartmentServlet", urlPatterns = "/DepartmentServlet")
public class DepartmentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/json; charset=utf-8");
        List<Department> list = new ArrayList<Department>();
        DepartmentService departmentServiceImpl = new DepartmentServiceImpl();
        list = departmentServiceImpl.queryDepartment();
        String str = JSON.toJSONString(list);
        System.out.println("str =" + str);
        PrintWriter out = response.getWriter();
        out.print(str);
    }
}
